package com.fs.jdk18test;

import org.junit.Test;

import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;

/**
 * @author shuai.fang
 * @date：2017-03-31
 * @description：
 */
public class TestJdk18 {

	@Test
	public void testLambda01() {
		Arrays.asList("a", "b", "c").forEach(e -> System.out.println(e));
	}

	@Test
	public void testLambda02() {
		Arrays.asList("a", "b", "c").forEach(new Consumer<String>() {
			@Override
			public void accept(String s) {
				System.out.println(s);
			}
		});
	}

	@Test
	public void testLambda03() {
		Arrays.asList("bd", "de").forEach((String s) -> System.out.println(s));
	}

	@Test
	public void testLambda04() {
		final String sep = ",";
		Arrays.asList("a", "b", "c").forEach(new Consumer<String>() {
			@Override
			public void accept(String s) {
				System.out.println(s + " " + sep);
			}
		});
	}

	@Test
	public void testLambda05() {
		TestFunctional testFunctional = new TestFunctional();
		testFunctional.test(s -> System.out.println(s), "asdfadsf");
	}

	@Test
	public void testClassMethod() {
		final Car car = Car.create(Car::new);
		final List<Car> carList = Arrays.asList(car);
		System.out.println(carList);
		carList.forEach(Car::collide);
		carList.forEach(Car::repair);
		carList.forEach(car::follow);
		carList.forEach(Car::collide);
		final Car police = Car.create(Car::new);
		carList.forEach(police::follow);
	}

	@Test
	public void test01() {
		Arrays.asList("1", "2").forEach(s -> {
			System.out.println(s);
		});
	}

	@Test
	public void test02() {
		Arrays.asList("1", "2").forEach((String s) -> {
			System.out.println(s);
		});
	}

	@Test
	public void testSortLambda() {
		Arrays.asList("1", "2", "3").sort((a, b) -> {
			return a.compareTo(b);
		});
	}

}
